$(function(){
    var ajaxFill = new Z.AjaxFill({
        url: Z.url('/backend/project/records'),
        templates: {
            list: $('#list-template'),
            none: '<tr><td colspan="7" style="text-align:center;">没有数据返回</td></tr>'
        },
        containers:{
            list: $('table.records tbody'),
            pageLinks: $('table.records tfoot td')
        },
        data: {
            pageSize: 20
        },
		after: function(){
			$('table.records tbody tr:odd').addClass('odd');
		}
    }),
    getId = function(element){
        return Z.parseInt($(element).parent().siblings().first().find(':checkbox').val());
    };
    
    $('a.delete').live('click',function(){
        var id = getId($(this));
        Z.confirm({
            content: '确定要删除吗',
            onConfirm: function(){
                Z.ajax({
                    url: Z.url('/backend/project/delete/'+id),
                    success: function(){
                        ajaxFill.reload();
                    }
                });
            }
        });
        return false;
    });
    
    $('a.home_display').live('click',function(){
        var id = getId($(this));
        Z.ajax({
            url: Z.url('/backend/project/display/'+id)
        });
    });
	
	$('a.order').live('click',function(){
		var id = getId($(this));
		Z.form({
			title: '排序输入框',
			content: $('#order-form').tmpl({id:id}),
			success: function(){
				ajaxFill.reload();
			}
		});
		return false;
	});
    
    ajaxFill.request();
    
    $('form.filter').submit(function(){
        ajaxFill.request({
            type: $(this).find('select[name=type]').val(),
            year: $(this).find('select[name=year]').val(),
            area: $(this).find('select[name=area]').val(),
            title: $(this).find('input[name=title]').val()
        });
        return false;
    });
});